def play(inp, iters):
    # cups[x] is the cup following the cup with value x
    cups = [0] * (max(inp) + 1)
    for a, b in zip(inp, inp[1:] + inp[:1]):
        cups[a] = b

    mod = max(inp)
    curr = inp[0]
    
    for _ in range(iters):
        # three pick up
        a = cups[curr]
        b = cups[a]
        c = cups[b]

        # get dest
        dest = (curr - 2) % mod + 1
        while dest in (a, b, c):
            dest = (dest - 2) % mod + 1

        # dest -> a -> b -> c
        after_dest = cups[dest]
        cups[dest] = a

        # curr -> (after c)
        after_c = cups[c]
        cups[curr] = after_c

        # c -> (after dest)
        cups[c] = after_dest

        # update curr
        curr = cups[curr]

    return cups

cups = [1,6,7,2,4,8,3,5,9]
cups.extend(range(10, 1_000_001))
p2 = play(cups, 10_000_000)
print(p2[1] * p2[p2[1]])